function backFresh(){
	var url = document.referrer;
	window.location = url;
}
//返回上一页面
function goBack(){
	history.back();
}
//将第一个表单提交
function submit(){
	//document.form[0].method="post";
	document.forms[0].submit();
}

function submit(formId){
	document.forms[formId].submit();
}

//刷新页面
function Reset(){
	document.location.reload();
}
//全选
function inputSltAll(obj){
	var liNode = obj.parentNode;
	var chkBoxList;
	try {
		chkBoxList = liNode.getElementsByTagName("input");
	}catch (e) {
		chkBoxList = new Array();
	}
	if(obj.checked){
		for(var i = 0;i < chkBoxList.length;i++){
			
			chkBoxList[i].checked = true;
		}
	}else{
		for(var i = 0;i < chkBoxList.length;i++){
			chkBoxList[i].checked = false;
		}
	}
}

function selectAll(checkName,cbSelectAll){
	//创建一个数组
 	var cbList=new Array();
	var cbSelect = document.getElementById(cbSelectAll);
	cbList = document.getElementsByName(checkName);
	if(cbSelect.checked){
		for(var i = 0;i < cbList.length;i++){
			
			cbList[i].checked = true;
		}
	}else{
		for(var i = 0;i < cbList.length;i++){
			cbList[i].checked = false;
		}
	}
}


//url转向
function hrefURL(url){
	document.location.href = url;
}

function searchClick(url){
	var select = document.getElementById("select");
	var key = ""; 
//	alert(select[select.selectedIndex].value);
	key = select[select.selectedIndex].value;
	var value = document.getElementById("txt_value").value;
	
	document.location.href = url+"searchKey="+key+"&searchValue="+value;
}

//获得checkbox中被选中项的id，以,隔开
function getParamsValue(checkBoxName){
	var cbList=new Array();
	var params = "";
	cbList = document.getElementsByName(checkBoxName);
	for(var i = 0;i < cbList.length;i++){
		if(cbList[i].checked){
			params += cbList[i].id + ",";
		}
	}
	//去掉最后的,
	if(params != ""){
		params = params.substring(0, params.length-1);
	}
	return params;
}

//单个checkbox选择提交
function checkBoxSubmit(checkBoxName,url,paramKey){
	var params = "";
	params = getParamsValue(checkBoxName);//
	if(params == ""){
		alert("请您选择操作对象！");
		return ;
	}
	if(params.search(",") > 0){
		alert("无法操作多个对象！");
		return ;
	}
//	var oldUrl = document.URL;//url oldUrl='/user/do.action?ssd' -> url='/user/'+url;
//	var flag = oldUrl.lastIndexOf("/",0);
//	url = oldUrl.substring(0, flag) + url;
	document.location.href = url + paramKey + "=" + params;//encodeURI()
}

//多个checkbox选择提交
function moreBoxSubmit(checkBoxName,url,paramKey){
	var params = getParamsValue(checkBoxName);
	if(params == ""){
		alert('请您选择操作对象！');
		return;
	}
//	var oldUrl = document.URL;//url oldUrl='/user/do.action?ssd' -> url='/user/'+url;
//	var flag = oldUrl.lastIndexOf("/",0);
//	url = oldUrl.substring(0, flag) + url;
	document.location.href = url + paramKey + "=" + params;//);encodeURI(
}

function resetValue(){
	try{
		document.getElementById('one').value = "";
	}catch(e){
	}
	try{
		document.getElementById('two').value = "";
	}catch(e){
	}
	try{
		document.getElementById('three').value = "";
	}catch(e){
	}
	try{
		document.getElementById('four').value = "";
	}catch(e){
	}
	try{
		var selectObj = document.getElementById('selOne');
		jsRemoveSelectedItemFromSelect(selectObj);
	}catch(e){
	}
	try{
		var selectObj = document.getElementById('selTwo');
		jsRemoveSelectedItemFromSelect(selectObj);
	}catch(e){
	}
	try{
		var selectObj = document.getElementById('selThree');
		jsRemoveSelectedItemFromSelect(selectObj);
	}catch(e){
	}
	try{
		var selectObj = document.getElementById('selFour');
		jsRemoveSelectedItemFromSelect(selectObj);
	}catch(e){
	}
}

function jsRemoveSelectedItemFromSelect(objSelect) {
	var length = objSelect.options.length - 1;
	for(var i = length; i >= 0; i--){
	    if(objSelect[i].selected == true){
	        objSelect.selected = false;
	    }
	}
	objSelect[0].selected = true;
}

function radioChange(obj){    //传入一个对象
	var parentObj = obj.parentNode;
	var radio_oj = parentObj.getElementsByTagName("input");
	for(var i=0;i<radio_oj.length;i++){
		radio_oj[i].checked = false; //修改选中状态
	}
	document.getElementById('enableId').value = obj.value;
	obj.checked = true;
}

/**
 * 删除，批量删除
 * @returns {Boolean}
 */
function deleteObj(checkBoxName,url,objtype){
	  var b = 0;
	    for(var i=0;i<document.getElementsByName(checkBoxName).length;i++){
	    	if(document.getElementsByName(checkBoxName)[i].checked){  		
	    		b++;
	    	}
	    }
	    askstr='你确定要删除所选信息吗？';
	    if(objtype == 'vidicon'){
	    	askstr='若要删除此点位信息，系统将自动删除与此点位相关的云台、雨刷、灯光、预置点等信息。'+askstr;
	    }
	    if(objtype == 'region'){
	    	askstr='删除此区域，系统将自动删除此区域相关部门所属区域，删除此区域后请及时设置跟此区域有关的部门的所属区域！'
	    }
	    if(objtype == 'facilityinfo'){
	    	askstr='若要删除此前端设备信息，系统将自动删除与此设备有关的监控点位以及与监控点位相关的云台、雨刷、灯光、预置点等信息。'+askstr;
	    }
	    if(b == 0){
	    	alert('请选中你要删除的信息!');
	    }else{
	    	if(confirm(askstr))	{
	    		document.form1.action=url;
	    		document.form1.submit();
	    		return true;
	    	}
	    	return false;
	    }
}
//监控点位分配机构
function vidiconAllot(checkBoxName,url,objtype){
	  var b = 0;
	    for(var i=0;i<document.getElementsByName(checkBoxName).length;i++){
	    	if(document.getElementsByName(checkBoxName)[i].checked){  		
	    		b++;
	    	}
	    }
	    askstr='你确定要为这些对象分配机构吗？';
	    if(b == 0){
	    	alert('请选中你要分配的对象!');
	    }else{
	    	if(confirm(askstr))	{
	    		document.form1.action=url;
	    		document.form1.submit();
	    		return true;
	    	}
	    	return false;
	    }
}
// 鼠标移到表格的某一行上,单行变色 
function cTo(ob)
{
	ob.style.background='#F4F4F4'; 
}
function cBack(ob,velocitycount)
{
	if(velocitycount){
		ob.style.background="#f5fafe"; 
	}else{
		ob.style.background=''; 
	}
}		


/**
 * 在obj中添加一个elementName元素。
 * @param obj
 * @param divId
 * @param elmentName
 * @return 返回添加的元素
 */
function createDiv(obj,divId,elmentName){
	var divObj = document.createElement(elmentName);
	divObj.setAttribute("id",divId);
	obj.appendChild(divObj);
	return divObj;
}

/**
 * 表单提交，默认的提交方式为原始form的method方式。
 * 当formAction 不为null或则空时，才更新form的action。
 * @param formId
 * @param formAction
 * @param method 表单的提交方式。
 */
function formSubmit(formId,formAction, method){
	var formObj = document.getElementById(formId);
	if(formAction != null || "" != formAction){
		formObj.action = formAction
	}
	if(method == "post"){
		formObj.method = method;
	}
	formObj.submit();
}

/**
 * 将parentObj下的所有input全部勾选或取消勾选。
 * @param chkObj
 * @param parentObj
 * @return
 */
function checkboxSelectAll(chkObj, parentObj){
	var inputArr = parentObj.getElementsByTagName("input");
	if(chkObj.checked){
		for(var i = 0; i < inputArr.length; i++){
			inputArr[i].checked = "true";
		}
	}else{
		for(var i = 0; i < inputArr.length; i++){
			inputArr[i].checked = "";
		}
	}
}

//折叠或展开.
foldShow = function(obj) {
	var clsVal = obj.attributes["class"].value;
	var ulObj = obj.parentNode.nextSibling;
	if( ulObj.nodeName != "UL" ){
		ulObj = ulObj.nextSibling;
	}
	if( clsVal == "clsFd" ){
		obj.attributes["class"].value = "opnFd";
		ulObj.style["display"] = "none";
	}else{
		obj.attributes["class"].value = "clsFd";
		ulObj.style["display"] = "block";
	}

}
//标记 li是否被点击 点击为 1，不点击为0
var flag = 0;

//onmounseover
function classUp(obj){
	if( obj.attributes["class"].value == "on" ){
		flag = 1;
	}else{
		obj.attributes["class"].value = "on";
		flag = 0;
	}
}

function classOut(obj){
	if(flag == 0){
		obj.attributes["class"].value = "";
	}else{
		flag = 1;
	}
}

function liClick(obj){
	var treeDiv = document.getElementById("dvLeft");
	var arrayLi = treeDiv.getElementsByTagName("li");
	for(var i = 0; i < arrayLi.length; i++){
		if(arrayLi[i].className == "on"){
			arrayLi[i].className = "";
		}
	}
	obj.attributes["class"].value = "on";
	flag = 1;
}

function  btnClick(obj){
	var treeDiv = document.getElementById("dvTab");
	var arrayLi = treeDiv.getElementsByTagName("table");
	for(var i = 0; i < arrayLi.length; i++){
		if(arrayLi[i].className == "on"){
			arrayLi[i].className = "";
		}
	}
	obj.attributes["class"].value = "on";
}

//div的隐藏与显示
function hider(){
	var div = document.getElementById('J_SearchBox');
	if (div.style.display == "none"){
		div.style.display="block";
		
    }else{
		div.style.display="none";
	}
}

function fGo(){

}

// dwr 实现下拉框动态填充值
//动态添加select中的项option: 
function addOption(sel,text,value){ 
	sel.options.add(new Option(text,value)); 
}

function selectItems(data,selectId){
	var objSelect = document.getElementById(selectId);
	//清空select中的值
//	objSelect.options.length = 0;
//	addOption(objSelect,'---请选择---','not');
	for(var i = 0; i < data.length; i++){
		var stpDt = data[i].split("=");
		addOption(objSelect,stpDt[1],stpDt[0]);
	}
//	DWRUtil.addOptions(selectId,data);
}

function selectItemsTwo(data,selectId){
	var objSelect = document.getElementById(selectId);
	//清空select中的值
	objSelect.options.length = 0;
	DWRUtil.addOptions(selectId,data);
}

function selectInput(obj){
	if(obj.options.length > 1){ return };
	var paraValue = obj.value;
	dwrSearchDao.getRoles(paraValue,function callBack(data){
		selectItems(data,obj.id);
	});
}

/**
 * 判断浏览器类型，返回浏览器信息对象。
 * 包括name浏览器名称，version浏览器版本，使用语言lang。
 * 
 */
function browserType(){
	var Browser_Name;   //浏览器名称
	var Browser_Version;    //浏览器版本识别数 
	var Browser_Lang;
	var Browser_Agent=navigator.userAgent; 
	//浏览器语言版本 
	var language = (navigator.appName == 'Netscape'?navigator.language:navigator.browserLanguage);  
     
	if (Browser_Agent.indexOf("MSIE") > 0) {
		Browser_Name = "IE";
	}else if (Browser_Agent.indexOf("Firefox") > 0) {
		Browser_Name = "Firefox";
	}else if (Browser_Agent.indexOf("Safari") > 0) {
		Browser_Name = "Safari";
	}else if (Browser_Agent.indexOf("Camino") > 0) {
		Browser_Name = "Camino";
	}else if (Browser_Agent.indexOf("Konqueror") > 0) {
		Browser_Name = "Konqueror";
	}else if (Browser_Agent.indexOf("Chrome") > 0) {
		Browser_Name = "Chrome";
	}else {
		Browser_Name = "Other";
	} 

	if (language.indexOf('en') > -1) {
		Browser_Lang = '英文';
	}else if (language.indexOf('zh') > -1) {
		Browser_Lang = '中文';
	}

	if (Browser_Name == 'IE'){ 
    	if (navigator.appVersion.match(/8./i) == '8.') {
			Browser_Version = '8';
		}
    	if (navigator.appVersion.match(/7./i) == '7.') {
			Browser_Version = '7';
		}else if (navigator.appVersion.match(/6./i) == '6.') {
			Browser_Version = '6';
		}
	}else { 
		Browser_Version =  navigator.appVersion;
	}
	return {
		name:Browser_Name,
		version:Browser_Version,
		lang:Browser_Lang
	};
}

/**
 * 获得鼠标的坐标，只支持IE。
 * @return
 */
function mouseCoords(){
	var ev = window.event;
//	if(ev.screenX || ev.screenX){
//		return {x:ev.screenX, y:ev.screenX};
//	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop     - document.body.clientTop
	};
}